try:
  from xml.etree import ElementTree # for Python 2.5 users
except ImportError:
  from elementtree import ElementTree
import gdata.calendar.service
import gdata.service
import atom.service
import gdata.calendar
import atom
import getopt
import sys
import string
import time


calendar_service = gdata.calendar.service.CalendarService()
calendar_service.email = 'erdogannamik@gmail.com'
calendar_service.password = '654152'
calendar_service.source = 'Google-Calendar_Python_Sample-1.0'
calendar_service.ProgrammaticLogin()



def InsertSingleEvent(calendar_service, title='One-time Tennis with Beth', 
                      content='Meet for a quick lesson', where='On the courts', 
                      start_time=None, end_time=None):  
    event = gdata.calendar.CalendarEventEntry()
    event.title = atom.Title(text=title)
    event.content = atom.Content(text=content)
    event.where.append(gdata.calendar.Where(value_string=where))

    if start_time is None:
      # Use current time for the start_time and have the event last 1 hour
      start_time = time.strftime('%Y-%m-%dT%H:%M:%S.000Z', time.gmtime())
      end_time = time.strftime('%Y-%m-%dT%H:%M:%S.000Z', time.gmtime(time.time() + 3600))
    event.when.append(gdata.calendar.When(start_time=start_time, end_time=end_time))
    minutes=10

    
    
   
    
    new_event = calendar_service.InsertEvent(event, '/calendar/feeds/default/private/full')
    
    print 'New single event inserted: %s' % (new_event.id.text,)
    print '\tEvent edit URL: %s' % (new_event.GetEditLink().href,)
    print '\tEvent HTML URL: %s' % (new_event.GetHtmlLink().href,)
    for a_when in new_event.when:
      if len(a_when.reminder) > 0:
        a_when.reminder[0].minutes = minutes
      else:
        a_when.reminder.append(gdata.calendar.Reminder(minutes=minutes))
    print 'Adding %d minute reminder to event' % (minutes,)
    return calendar_service.UpdateEvent(new_event.GetEditLink().href, new_event)
   
    return new_event


InsertSingleEvent(calendar_service, title='Sip termin yeni 08-0024', 
                      content='2246 order fermuar', where='BS Tekstil', 
                      start_time='2008-06-16T02:00:00.000-22:40', end_time='2008-06-16T02:00:00.000-22:58')


    
